package com.xxxx.crm.controller;

import com.xxxx.crm.annoation.RequiredPermission;
import com.xxxx.crm.base.BaseController;
import com.xxxx.crm.base.ResultInfo;
import com.xxxx.crm.enums.StateStatus;
import com.xxxx.crm.query.CustomerQuery;
import com.xxxx.crm.query.DataDicQuery;
import com.xxxx.crm.query.DataDicQuery;
import com.xxxx.crm.service.DataDicService;
import com.xxxx.crm.service.DataDicService;
import com.xxxx.crm.utils.CookieUtil;
import com.xxxx.crm.utils.LoginUserUtil;
import com.xxxx.crm.vo.DataDic;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
(。_。)
 */
@Controller
@RequestMapping("data_dic")
public class DataDicController extends BaseController {
    @Resource
    private DataDicService dataDicService;

    /**
     * 进入字典管理页面
     */
    @RequestMapping("index")
    public String index(){
        return "dataDic/data_dic";
    }


    /**
     * 分页条件查询客户列表
     */
    @RequestMapping("list")
    @ResponseBody
    public Map<String,Object> queryDataDicByParams(DataDicQuery dataDicQuery) {
        return dataDicService.queryDataDicByParams(dataDicQuery);
    }

    /**
     * 进入添加/修改字典数据页面
     */
    @RequestMapping("toDataDicPage")
    public String toDataDicPage(Integer dataDicId, HttpServletRequest request) {

        // 判断dataDicId是否为空
        if (dataDicId != null) {
            // 通过ID查询字典数据
            DataDic dataDic = dataDicService.selectByPrimaryKey(dataDicId);
            // 将数据设置到请求域中
            request.setAttribute("dataDic",dataDic);
        }
        return "dataDic/add_update";
    }

    /**
     * 添加字典
     */
    @PostMapping("add")
    @ResponseBody
    public ResultInfo addDataDic(DataDic dataDic) {
        // 调用Service层的添加方法
        dataDicService.addDataDic(dataDic);
        return success("字典数据添加成功！");
    }


    /**
     * 更新字典
     */
    @PostMapping("update")
    @ResponseBody
    public ResultInfo updateDataDic(DataDic dataDic) {
        // 调用Service层的添加方法
        dataDicService.updateDataDic(dataDic);
        return success("字典数据更新成功！");
    }


    /**
     * 删除字典
     */
    @PostMapping("delete")
    @ResponseBody
    public ResultInfo deleteDataDic(Integer[] ids) {
        // 调用Service层的删除方法
        dataDicService.deleteBatch(ids);
        return success("字典数据删除成功！");
    }
}
